package com.example.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author zhangs
 * @version v1.0
 * @decription 实时获取在线人数
 * @date 2021/3/24 18:51
 **/
@WebServlet("/demo07")
public class Demo07 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        Object onlinePersons = session.getServletContext().getAttribute("onlineCount");
        resp.getWriter().print("当前在线人数：" + onlinePersons);
    }
}
